#include "client.h"

client::client(QWidget* parent)
    : QMainWindow(parent)
    , ui(new Ui_client)
{
    ui->setupUi(this);
    socket = new QTcpSocket(this);
}

client::~client()
{
    delete ui; 
}


void client::on_pushButton_2_clicked()
{
    QString ip_ = ui->lineEdit->text();
    QString port_ = ui->lineEdit_2->text();

    socket->connectToHost(ip_, port_.toShort());

    connect(socket, &QTcpSocket::connected, [this]() {

        QMessageBox::information(this, "连接提示", "已连接服务器");

        this->hide();
        chat *chatWindow = new chat(socket);
        chatWindow->show();
    });

    connect(socket, &QTcpSocket::disconnected, [this]() {
        QMessageBox::information(this, "连接提示", "已断开服务器");
    });
}


void client::on_pushButton_clicked()
{
    this->close();
}

